All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.text.StyleContext
java.lang.Object
|
+----com.sun.java.swing.text.StyleContext
- public class StyleContext
- extends Object
- implements Serializable, AbstractDocument. AttributeContext
A pool of styles and their associated resources. This class determines
the lifetime of a group of resources by being a container that holds
caches for various resources such as font and color that get reused
by the various style definitions. This can be shared by multiple
documents if desired to maximize the sharing of related resources.
This class also provides efficient support for small sets of attributes
and compresses them by sharing across uses and taking advantage of
their immutable nature. Since many styles are replicated, the potential
for sharing is significant, and copies can be extremely cheap.
Larger sets reduce the possibility of sharing, and therefore revert
automatically to a less space-efficient implementation.
Warning: serialized objects of this class will not be compatible with
future swing releases. The current serialization support is appropriate
for short term storage or RMI between Swing1.0 applications. It will
not be possible to load serialized Swing1.0 objects with future releases
of Swing. The JDK1.2 release of Swing will be the compatibility
baseline for the serialized form of Swing objects.
-
DEFAULT_STYLE
- The name given to the default logical style attached
to paragraphs.
-
StyleContext()
- Creates a new StyleContext object.
-
addAttribute(AttributeSet, Object, Object)
- Adds an attribute to the given set, and returns
the new representative set.
-
addAttributes(AttributeSet, AttributeSet)
- Adds a set of attributes to the element.
-
addChangeListener(ChangeListener)
- Adds a listener to track when styles are added
or removed.
-
addStyle(String, Style)
- Adds a new style into the style hierarchy.
-
getCompressionThreshold()
- Returns the maximum number of key/value pairs to try and
compress into unique/immutable sets.
-
getDefaultStyleContext()
- Returns default AttributeContext shared by all documents that
don't bother to define/supply their own context.
-
getEmptySet()
- Fetches an empty AttributeSet.
-
getFont(AttributeSet)
- Gets the font from an attribute set.
-
getFont(String, int, int)
- Gets a new font.
-
getFontMetrics(Font)
- Returns font metrics for a font.
-
getStyle(String)
- Fetches a named style previously added to the document
-
getStyleNames()
- Fetches the names of the styles defined.
-
readAttributeSet(ObjectInputStream, MutableAttributeSet)
- Reads a set of attributes from the given object input
stream that have been previously written out with
writeAttributeSet
.
-
reclaim(AttributeSet)
- Returns a set no longer needed by the MutableAttributeSet implmentation.
-
registerStaticAttributeKey(Object)
- Registers an object as a static object that is being
used as a key in attribute sets.
-
removeAttribute(AttributeSet, Object)
- Removes an attribute from the set.
-
removeAttributes(AttributeSet, AttributeSet)
- Removes a set of attributes for the element.
-
removeAttributes(AttributeSet, Enumeration)
- Removes a set of attributes for the element.
-
removeChangeListener(ChangeListener)
- Removes a listener that was tracking styles being
added or removed.
-
removeStyle(String)
- Removes a named style previously added to the document.
-
toString()
- Converts a StyleContext to a String.
-
writeAttributeSet(ObjectOutputStream, AttributeSet)
- Writes a set of attributes to the given object stream
for the purpose of serialization.
DEFAULT_STYLE
public static final String DEFAULT_STYLE
- The name given to the default logical style attached
to paragraphs.
StyleContext
public StyleContext()
- Creates a new StyleContext object.
getDefaultStyleContext
public static final StyleContext getDefaultStyleContext()
- Returns default AttributeContext shared by all documents that
don't bother to define/supply their own context.
- Returns:
- the context
addStyle
public Style addStyle(String nm,
Style parent)
- Adds a new style into the style hierarchy. Style attributes
resolve from bottom up so an attribute specified in a child
will override an attribute specified in the parent.
- Parameters:
- nm - the name of the style (must be unique within the
collection of named styles in the document). The name may
be null if the style is unnamed, but the caller is responsible
for managing the reference returned as an unnamed style can't
be fetched by name. An unnamed style may be useful for things
like character attribute overrides such as found in a style
run.
- parent - the parent style. This may be null if unspecified
attributes need not be resolved in some other style.
- Returns:
- the created style
removeStyle
public void removeStyle(String nm)
- Removes a named style previously added to the document.
- Parameters:
- nm - the name of the style to remove
getStyle
public Style getStyle(String nm)
- Fetches a named style previously added to the document
- Parameters:
- nm - the name of the style
- Returns:
- the style
getStyleNames
public Enumeration getStyleNames()
- Fetches the names of the styles defined.
- Returns:
- the list of names as an enumeration
addChangeListener
public void addChangeListener(ChangeListener l)
- Adds a listener to track when styles are added
or removed.
- Parameters:
- l - the change listener
removeChangeListener
public void removeChangeListener(ChangeListener l)
- Removes a listener that was tracking styles being
added or removed.
- Parameters:
- l - the change listener
getFont
public Font getFont(AttributeSet attr)
- Gets the font from an attribute set. This is
implemented to try and fetch a cached font
for the given AttributeSet, and if that fails
the font features are resolved and the
font is fetched from the low-level font cache.
- Parameters:
- attr - the attribute set
- Returns:
- the font
getFont
public Font getFont(String family,
int style,
int size)
- Gets a new font. This returns a Font from a cache
if a cached font exists. If not, a Font is added to
the cache. This is basically a low-level cache for
1.1 font features.
- Parameters:
- family - the font family (such as "Monospaced")
- style - the style of the font (such as Font.PLAIN)
- size - the point size >= 1
- Returns:
- the new font
getFontMetrics
public FontMetrics getFontMetrics(Font f)
- Returns font metrics for a font.
- Parameters:
- f - the font
- Returns:
- the metrics
addAttribute
public synchronized AttributeSet addAttribute(AttributeSet old,
Object name,
Object value)
- Adds an attribute to the given set, and returns
the new representative set.
This method is thread safe, although most Swing methods
are not. Please see
Threads
and Swing for more information.
- Parameters:
- old - the old attribute set
- name - the non-null attribute name
- value - the attribute value
- Returns:
- the updated attribute set
- See Also:
- addAttribute
addAttributes
public synchronized AttributeSet addAttributes(AttributeSet old,
AttributeSet attr)
- Adds a set of attributes to the element.
This method is thread safe, although most Swing methods
are not. Please see
Threads
and Swing for more information.
- Parameters:
- old - the old attribute set
- attr - the attributes to add
- Returns:
- the updated attribute set
- See Also:
- addAttribute
removeAttribute
public synchronized AttributeSet removeAttribute(AttributeSet old,
Object name)
- Removes an attribute from the set.
This method is thread safe, although most Swing methods
are not. Please see
Threads
and Swing for more information.
- Parameters:
- old - the old set of attributes
- name - the non-null attribute name
- Returns:
- the updated attribute set
- See Also:
- removeAttribute
removeAttributes
public synchronized AttributeSet removeAttributes(AttributeSet old,
Enumeration names)
- Removes a set of attributes for the element.
This method is thread safe, although most Swing methods
are not. Please see
Threads
and Swing for more information.
- Parameters:
- old - the old attribute set
- names - the attribute names
- Returns:
- the updated attribute set
- See Also:
- removeAttributes
removeAttributes
public synchronized AttributeSet removeAttributes(AttributeSet old,
AttributeSet attrs)
- Removes a set of attributes for the element.
This method is thread safe, although most Swing methods
are not. Please see
Threads
and Swing for more information.
- Parameters:
- old - the old attribute set
- attrs - the attributes
- Returns:
- the updated attribute set
- See Also:
- removeAttributes
getEmptySet
public AttributeSet getEmptySet()
- Fetches an empty AttributeSet.
- Returns:
- the set
reclaim
public void reclaim(AttributeSet a)
- Returns a set no longer needed by the MutableAttributeSet implmentation.
This is useful for operation under 1.1 where there are no weak
references. This would typically be called by the finalize method
of the MutableAttributeSet implementation.
This method is thread safe, although most Swing methods
are not. Please see
Threads
and Swing for more information.
- Parameters:
- a - the set to reclaim
getCompressionThreshold
protected int getCompressionThreshold()
- Returns the maximum number of key/value pairs to try and
compress into unique/immutable sets. Any sets above this
limit will use hashtables and be a MutableAttributeSet.
- Returns:
- the threshold
toString
public String toString()
- Converts a StyleContext to a String.
- Returns:
- the string
- Overrides:
- toString in class Object
writeAttributeSet
public static void writeAttributeSet(ObjectOutputStream out,
AttributeSet a) throws IOException
- Writes a set of attributes to the given object stream
for the purpose of serialization. This will take
special care to deal with static attribute keys that
have been registered wit the
registerStaticAttributeKey
method.
Any attribute key not regsitered as a static key
will be serialized directly. All values are expected
to be serializable.
- Parameters:
- out - the output stream
- a - the attribute set
- Throws: IOException
- on any I/O error
readAttributeSet
public static void readAttributeSet(ObjectInputStream in,
MutableAttributeSet a) throws ClassNotFoundException, IOException
- Reads a set of attributes from the given object input
stream that have been previously written out with
writeAttributeSet
. This will try to restore
keys that were static objects to the static objects in
the current virtual machine considering only those keys
that have been registered with the
registerStaticAttributeKey
method.
The attributes retrieved from the stream will be placed
into the given mutable set.
- Parameters:
- in - the object stream to read the attribute data from.
- a - the attribute set to place the attribute
definitions in.
- Throws: ClassNotFoundException
- passed upward if encountered
when reading the object stream.
- Throws: IOException
- passed upward if encountered when
reading the object stream.
registerStaticAttributeKey
public static void registerStaticAttributeKey(Object key)
- Registers an object as a static object that is being
used as a key in attribute sets. This allows the key
to be treated specially for serialization.
For operation under a 1.1 virtual machine, this
uses the value returned by toString
concatenated to the classname. The value returned
by toString should not have the class reference
in it (ie it should be reimplemented from the
definition in Object) in order to be the same when
recomputed later.
- Parameters:
- key - the non-null object key
All Packages Class Hierarchy This Package Previous Next Index